package consumer.json_utils;

import io.confluent.kafka.consumer.entities.CurrentAlarmBean;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * Created by taotao on 2018/5/3.
 */
public class Str2Date {
    public static void main(String[] args) {
        String dateStr = "2018-05-03T08:07:15.970467";
        System.out.println(str2Date(dateStr));
        CurrentAlarmBean currentAlarmBean = new CurrentAlarmBean();
        currentAlarmBean.setAlarmraisedtime(str2Date(dateStr));
        System.out.println(currentAlarmBean.getAlarmraisedtime());
    }
    public static Date str2Date(String dateStr) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("", Locale.SIMPLIFIED_CHINESE);
        dateFormat.applyPattern("yyyy-MM-dd'T'HH:mm:ss");
        Date date = null;
        try {
            date = dateFormat.parse(dateStr);
            System.out.println(date.toString());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}
